AI Verified

Name

Display Prices With + Without Tax

About

This code snippet is a part of a WordPress plugin or theme customization that modifies the display of prices in the WooCommerce plugin, specifically the suffix that appears after the product price. The `add_filter` function is a WordPress hook that allows you to modify the output of a specific function or filter. In this case, it hooks into the `woocommerce_get_price_suffix` filter with a priority of 99 (a higher number means it executes later in the filtering process) and accepts 4 parameters. The function `bbloomer_add_price_suffix_price_inc_tax` is the callback function that is executed when the `woocommerce_get_price_suffix` filter is triggered. It takes four parameters: `$suffix`, `$product`, `$price`, and `$qty`. Within the callback function, the code modifies the `$suffix` variable, which represents the price suffix that is displayed after the product price. The new suffix is composed of two small HTML elements wrapped around the text and the calculated price, indicating the inclusion or exclusion of taxes. Here's a breakdown of what happens in the callback function: 1. The `$suffix` variable is assigned a new value. 2. The new value consists of a text string `' <small>ex. TAX</small> - '` followed by the price including tax calculated using the `wc_get_price_including_tax()` function, and finally, another small HTML element `'<small>inc. TAX</small>'`. 3. The modified `$suffix` variable is then returned from the function. By using this code, the output of the product price in WooCommerce will include a small HTML text indicating whether the price is excluding or including tax, as specified in the suffix.

Language

PHP

Rating

Voted: 0 by 0 user(s)

Link for further information:

The author has provided the following URL that may be helpful to setting up or using this snippet:

https://www.businessbloomer.com/woocommerce-prices-inc-and-ex-tax/

Codevault

justin's vault

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

Snippet Source:

https://www.businessbloomer.com/woocommerce-prices-inc-and-ex-tax/

History

Last modified:

16/06/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Display Prices With + Without Tax

 
                    
1add_filter( 'woocommerce_get_price_suffix', 'bbloomer_add_price_suffix_price_inc_tax', 99, 4 );
2 
3function bbloomer_add_price_suffix_price_inc_tax( $suffix, $product, $price, $qty ){
4 $suffix = ' <small>ex. TAX</small> - ' . wc_price( wc_get_price_including_tax( $product ) ) . ' <small>inc. TAX</small>';
5 return $suffix;
6}

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

2

WooCommerce Create Coupon Code Automatically After Purchase

Added: 1 year ago

Last Updated: 1 day ago

This snippet automatically creates a coupon code when an order is placed and lets the customer know to share said coupon code to give their friend money off. Specifically, this code creates a coupon c...

WooCommerce

AI Verified

0

Add Woo Delivery Date Field

Added: 5 months ago

Last Updated: 5 months ago

Add a mandatory delivery date field between 2 to 7 days from today.

WooCommerce

AI Verified

0

Remove WooCommerce Cart Images

Added: 7 months ago

Last Updated: 7 months ago

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

General

AI Verified

3

Default featured image

Added: 1 year ago

Last Updated: 3 days ago

This code defines a function named default_post_metadata__thumbnail_id that modifies the value of the _thumbnail_id metadata field for a post. The function takes five arguments: $value: The current...

WordPress Admin

AI Verified

2

Completely Disable Comments

Added: 1 year ago

Last Updated: 4 months ago

This will disable comments on the entire site

WordPress Admin

AI Verified

1

Disable Automatic Updates

Added: 1 year ago

Last Updated: 9 months ago

This will disable automatic updates